/******************************************************************************************************
Copyright (C) 2013 Mestrelab Research S.L. All rights reserved.

This file is part of the MNova scripting toolkit.

Authorized users of MNova Software may use this file freely, but this file is provided AS IS
with NO WARRANTY OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE.
*****************************************************************************************************/

/*globals Dialog, GroupBox, RadioButton, Application*/
/*jslint plusplus: true, indent: 4*/

//! This function gets a list of arguments and constructs a radio buttons dialog. The first argument is used as dialog title
function radioButtonDialog(aTitle, aStringList, aDefaultChecked) {
	"use strict";
	if (aTitle === undefined || aStringList === undefined) {
		return;
	}
	var gBox, rButtons, i,
		diag = new Dialog();
	diag.title = aTitle;
	gBox = new GroupBox();
	diag.add(gBox);
	rButtons = [];
	for (i = 0; i < aStringList.length; i++) {
		rButtons[i] = new RadioButton();
		rButtons[i].text = aStringList[i];
		if (aDefaultChecked !== undefined  && rButtons[i].text === aDefaultChecked) {
			rButtons[i].checked = true;
		} else if (i === 0) {
			rButtons[i].checked = true;
		}
		gBox.add(rButtons[i]);
    }
	if (diag.exec()) {
		for (i = 0; i < rButtons.length; i++) {
			if (rButtons[i].checked) {
				return rButtons[i].text;
			}
		}
	}
	return undefined;
}

//! Shows a dialog with a text editor. Returns the text in the editor if accepted or an empty string if cancelled
function textEditDialog(aTitle, aDefaultText) {
	"use strict";
	var diag = Application.loadUiFile("ricares:dialogs_EditText.ui");
	diag.windowTitle = aTitle;
	diag.widgets.plainTextEdit.plainText = aDefaultText;
	if (diag.exec()) {
		return diag.widgets.plainTextEdit.plainText;
	} else {
		return '';
	}
}
